#include "评委打分.h"


int score;
Person::Person(string name,int score) {
    this->m_name = name;
    this->m_score = score;
}

void createPerson(vector<Person> &v) {
    string name1 = "ABCDE";
    for (int i = 0; i < 5 ;i++) { //从A选手遍历完
        string name = "选手 ";
        name += name1[i];
        Person p(name,score);  //类里定义一个p，传入写好的参数
        v.push_back(p);
    }
}

void setscore(vector<Person> &v) {  //更改上一个写好的参数里面的score，用随机数来获取
    for (vector<Person>::iterator it = v.begin();it != v.end();it++) {
        //评委打分（随机）
        deque<int> d;
        for (int i = 0; i < 10;i++) {
            score = rand() % 41 + 60;
            d.push_back(score);
        }

        sort(d.begin(),d.end());
        d.pop_front();
        d.pop_back();

        int sum = 0;
        for (auto it = d.begin();it != d.end();it++) {
            sum += *it;
        }
        int avr = sum / d.size();
        (*it).m_score = avr;
    };
}

void showret(vector<Person> &v) {
    for (auto rit = v.begin();rit != v.end();rit++) {
        cout<<rit->m_name<<"的最终得分为: "<<rit->m_score<<endl;
    }
}

int main() {
    //随机打分，节省时间
    srand((unsigned int)time(NULL));

    //创建5名选手
    vector<Person> v;

    //创建选手信息
    createPerson(v);

    //获取评委打分
    setscore(v);

    //打印最终成绩
    showret(v);
    return 0;
}